package com.jcl.recruit.corp.dao;

import com.jcl.core.db.DatabaseContext;
import com.jcl.recruit.corp.mapper.SubcompanyMapper;
import com.jcl.recruit.corp.model.Subcompany;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SubcompanyDao implements SubcompanyMapper {

    @Autowired
    private SubcompanyMapper subcompanyMapper;

    @Override
    public List<Subcompany> selectAllComanyInfosBySuperId(Integer superId) {
        DatabaseContext.setCurrentContext();
        return subcompanyMapper.selectAllComanyInfosBySuperId(superId);
    }

    @Override
    public Subcompany findOneByCode(String code) {
        DatabaseContext.setContext(code);
        return subcompanyMapper.findOneByCode(code);
    }

    @Override
    public List<Subcompany> findOneByEmail(String email,
                                           String name) {
        DatabaseContext.setCurrentContext();
        return subcompanyMapper.findOneByEmail(email, name);
    }

    @Override
    public Subcompany findOneById(Integer id) {
        DatabaseContext.setCurrentContext();
        return subcompanyMapper.findOneById(id);
    }

    @Override
    public int add(Subcompany company) {
        DatabaseContext.setContext(company.getCode());
        return subcompanyMapper.add(company);
    }

    @Override
    public int update(Subcompany company) {
        DatabaseContext.setContext(company.getCode());
        return subcompanyMapper.update(company);
    }

    @Override
    public int updateAddUser(String corpCode,
                             Integer id,
                             Integer userId) {
        DatabaseContext.setContext(corpCode);
        return subcompanyMapper.updateAddUser(corpCode, id, userId);
    }
}
